<template>
    <div class="r-table">
        <div class="r-row r-header">
            <div class="r-coll c-title-5" v-for="(column, index) in props.tableConfig.columns"
                :style="{ flex: props.tableConfig.flex[index] }">
                <slot name="header" :column="column" :index="index">{{ column }}</slot>
            </div>
        </div>
        <JEmpty v-if="props.tableData.length == 0"></JEmpty>
        <template v-else>
            <div class="r-row r-body" v-for="(row, rowIndex) in props.tableData" :key="rowIndex">
                <div class="r-coll c-title-4" v-for="(cell, cellIndex) in row"
                    :style="{ flex: props.tableConfig.flex[cellIndex] }">
                    <slot name="row" :row="row" :rowIndex="rowIndex" :cell="cell" :cellIndex="cellIndex">{{ cell }}</slot>
                </div>
            </div>
            <JLoading v-if="flag" />
            <v-pagination @update:modelValue="handlePageChange" v-show="Math.ceil(tableTotal / speed) > 1"
                :length="Math.ceil(tableTotal / speed)" :total-visible="5" v-model="idx"></v-pagination>
        </template>
    </div>
</template>

<script lang="ts" setup>
import JLoading from "@/components/j-loding/index.vue";
 
import JEmpty from "@/components/j-empty/index.vue";
import { ref } from "vue";
const idx = ref(1);
const speed = 10;
const props = defineProps({
    tableData: {
        type: Array,
        required: true
    },
    tableConfig: {
        type: Object,
        required: true
    },
    tableTotal: {
        type: Number,
        required: true,
        default: 0
    },
    flag:{
        type: Boolean,
        required: true,
        default: false
    }
});
const emit = defineEmits(["getData"])
function handlePageChange(page: any) {
    emit("getData", page,speed)
}
</script>

<style lang="less" scoped>
@import url("./index.less");
</style>
